import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import LoveApp from '../views/LoveApp.vue'
import ManusApp from '../views/ManusApp.vue'
import Login from '../views/Login.vue'
import UserProfile from '../views/UserProfile.vue'
import EmailAuth from '../views/EmailAuth.vue'
import { isLoggedIn } from '../state/auth'

const routes = [
  {
    path: '/',
    redirect: '/invitation'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/love-app',
    name: 'LoveApp',
    component: LoveApp,
    meta: { requiresAuth: true }
  },
  {
    path: '/manus-app',
    name: 'ManusApp',
    component: ManusApp,
    meta: { requiresAuth: true }
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/profile',
    name: 'UserProfile',
    component: UserProfile,
    meta: { requiresAuth: true }
  },
  {
    path: '/first-login-setup/:userAccount',
    name: 'FirstLoginSetup',
    component: () => import('../views/FirstLoginSetup.vue')
  },
  {
    path: '/profile-setup/:userAccount',
    name: 'ProfileSetup',
    component: () => import('../views/ProfileSetup.vue')
  },
  {
    path: '/invitation',
    name: 'invitationPage',
    component: () => import('../views/InvitationPage.vue')
  },
  {
    path: '/email-auth',
    name: 'EmailAuth',
    component: EmailAuth,
    meta: {
      requiresAuth: false
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// router.beforeEach((to, from, next) => {
//   if (to.meta.requiresAuth && !isLoggedIn.value) {
//     next({ name: 'Login', query: { redirect: to.fullPath } })
//   } else {
//     next()
//   }
// })

export default router 